package com.lagou.com.lagou.homework.Modules4.item1;

import java.util.Objects;

/**
 * 其中学生的信息有：学号、姓名、年龄。
 */
public class Student implements java.io.Serializable{
    private static final long serialVersionUID = -4017640871627564105L;
    //继承此接口启动序列化

    private int num;
    private String name;
    private int age;

    public Student() {
    }

    public Student(int num, String name, int age) throws StudentIdException, StudentAgeException {
        setNum(num);
        this.name = name;
        setAge(age);
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) throws StudentIdException {
        if (num > 0){
            this.num = num;
        }else{
            throw new StudentIdException("Input StudentId Eeror!");
            //System.out.println("学号输入有误");
        }

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {

        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws StudentAgeException {
        if (age > 0 && age < 120){
            this.age = age;
        }else{
            throw new StudentAgeException("Input Student Age Error!");
            //System.out.println("输入的年龄有误！");
        }

    }

    @Override
    public String toString() {
        return "学生信息{" +
                "学号=" + num +
                ", 名字='" + name + '\'' +
                ", 年龄=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return num == student.num/* &&
                age == student.age &&
                Objects.equals(name, student.name)*/;
    }

    @Override
    public int hashCode() {
        return Objects.hash(num, name, age);
    }
}
